using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Linq.Expressions;
using System.Reflection;
using System.Collections;
using System.Collections.ObjectModel;
using System.Runtime.Serialization.Formatters.Binary;
using System.Runtime.Serialization;
using System.IO;

//[DataContract]
[Serializable]
public abstract class DTOBase
{
    #region Properties use in progress

    /// <summary>
    /// Creating status
    /// </summary>
    [NonSerialized]
    private bool _isNew = false;
    public bool IsNew
    {
        get { return _isNew; }
        set
        {
            if (_isNew != value)
            {
                OnIsNewChanging(value);
                _isNew = value;
                OnIsNewChanged();
            }
        }
    }

    /// <summary>
    /// Editing status
    /// </summary>
    [NonSerialized]
    private bool _isEdited = false;
    public bool IsEdited
    {
        get { return _isEdited; }
        set
        {
            if (_isEdited != value)
            {
                OnIsEditChanging(value);
                _isEdited = value;
                OnIsEditChanged();
            }
        }
    }

    /// <summary>
    /// Deleted status
    /// </summary>
    [NonSerialized]
    private bool _isDeleted = false;
    public bool IsDeleted
    {
        get { return _isDeleted; }
        set
        {
            if (_isDeleted != value)
            {
                OnIsDeletedChanging(value);
                _isDeleted = value;
                OnIsDeletedChanged();
            }
        }
    }

    /// <summary>
    /// Checked status
    /// </summary>
    [NonSerialized]
    private bool _isChecked = false;
    public bool IsChecked
    {
        get { return _isChecked; }
        set
        {
            if (_isChecked != value)
            {
                OnIsCheckedChanging(value);
                _isChecked = value;
                OnIsCheckedChanged();
            }
        }
    }

    /// <summary>
    /// Selected status
    /// </summary>
    [NonSerialized]
    private bool _isSelected = false;
    public bool IsSelected
    {
        get { return _isSelected; }
        set
        {
            if (_isSelected != value)
            {
                OnIsSelectedChanging(value);
                _isSelected = value;
                OnIsSelectedChanged();
            }
        }
    }

    /// <summary>
    /// IsError status
    /// </summary>
    [NonSerialized]
    private bool _isError = false;
    public bool IsError
    {
        get { return _isError; }
        set
        {
            if (_isError != value)
            {
                OnIsErrorChanging(value);
                _isError = value;
                OnIsErrorChanged();
            }
        }
    }

    //public bool? ThreeState
    //{
    //    get
    //    {
    //        if (_isNew)
    //            return true;
    //        if (_isEdited)
    //            return false;
    //        return null;
    //    }
    //}

    #endregion

    #region Methods

    #region Extension Methods

    protected virtual void OnIsNewChanging(object value) { }
    protected virtual void OnIsNewChanged() { }

    protected virtual void OnIsEditChanging(object value) { }
    protected virtual void OnIsEditChanged() { }

    protected virtual void OnIsDeletedChanging(object value) { }
    protected virtual void OnIsDeletedChanged() { }

    protected virtual void OnIsCheckedChanging(object value) { }
    protected virtual void OnIsCheckedChanged() { }

    protected virtual void OnIsSelectedChanging(object value) { }
    protected virtual void OnIsSelectedChanged() { }

    protected virtual void OnIsErrorChanging(object value) { }
    protected virtual void OnIsErrorChanged() { }

    #endregion

    #region Change IsEdit

    protected virtual void OnChanged()
    {
        if (!IsEdited) IsEdited = true;
    }

    #endregion

    #endregion
}
